package com.jz.control;

import com.jz.entity.CourseDetail;
import com.jz.entity.ResultVo;
import com.jz.service.CourseDetailService;
import com.jz.service.impl.CourseDetailServiceImpl;
import com.jz.utils.RespJsonUtils;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet("*.cd")
@MultipartConfig
public class CourseDetailServlet extends BaseServlet {
    //多态 章节多态的service
     CourseDetailService cds = new CourseDetailServiceImpl();
     public void addCourseDetail(HttpServletRequest req, HttpServletResponse resp) throws Exception {
         //获取表单数据
         Map<String, String[]> map = req.getParameterMap();
         //章节的实体类
         CourseDetail cd = new CourseDetail();
         //表单数据与对象属性的映射
         BeanUtils.populate(cd,map);//映射完成后,cd里面的属性已经被赋值
         //调用章节的添加方法
         boolean b = cds.addCourseDetail(cd);
         ResultVo rv = null;
         if (b){
            rv= new ResultVo(200,"课程章节添加成功",null);
            //一般情况下
            //这里增删改查不用传回数据,也就是rData
             //查询成功需要返回数据
         }else{
            rv =  new ResultVo(500,"课程章节添加失败",null);
         }
         //解析数据并且相应
         RespJsonUtils.objectToJson(rv,resp);

     }

}
